<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:t="http://www.pagac.cz/jsf"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
 <h:head></h:head>
 <h:body>
    <ui:composition template="/WEB-INF/templates/template-insystem.xhtml">

        <!-- Toolbar -->
        <ui:define name="toolbar-place">
            <t:toolbar>
                <t:icon iconName="home" action="goHome" label="#{msgs['toolbar.home']}" />
                <t:icon iconName="back" action="project/list" label="#{msgs['toolbar.back']}" />
                <t:icon iconName="print" action="printPage" label="#{msgs['toolbar.print']}" />
                <t:separator />
                <t:icon iconName="add" action="newTask" backingBean="#{projectManager}" bean="true"
                        label="#{msgs['user.project.list.actions.newtask']}"
                        renderedBean="#{taskManager}" renderedAction="true" />
                <t:separator />
                <!-- Granularity selection -->
                <t:icon iconName="more" action="more" backingBean="#{taskManager}" label="#{msgs['toolbar.more']}"
                        bean="true" ajaxExecute="@this" ajaxRender="@all" formId="moreNavLink"
                        renderedBean="#{taskManager.paginator}" renderedAction="moreSafe" />
                <t:icon iconName="less" action="less" backingBean="#{taskManager}" label="#{msgs['toolbar.less']}"
                        bean="true" ajaxExecute="@this" ajaxRender="@all" formId="lessNavLink"
                        renderedBean="#{taskManager.paginator}" renderedAction="remainsSomething" />
                <t:separator />
                <!-- AJAX navigation -->
                <t:icon iconName="first" action="first" backingBean="#{taskManager}" label="#{msgs['toolbar.first']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="firstNavLink"
                    renderedBean="#{taskManager.paginator}" renderedAction="hasPreviousPage" />
                <t:icon iconName="prev" action="previous" backingBean="#{taskManager}" label="#{msgs['toolbar.previous']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="prevNavLink"
                    renderedBean="#{taskManager.paginator}" renderedAction="hasPreviousPage" />
                <t:textIcon>
                    <h:outputFormat value="&nbsp;#{msgs['app.paging.displayInfo']}">
                        <f:param value="#{taskManager.paginator.pageFirstItem + 1}" />
                        <f:param value="#{taskManager.paginator.pageLastItem + 1}" />
                        <f:param value="#{taskManager.paginator.itemsCount}" />
                    </h:outputFormat>
                    <h:outputText value=" (#{msgs['app.paging.page']} #{taskManager.paginator.actualPage + 1}) " />
                </t:textIcon>
                <t:icon iconName="next" action="next" backingBean="#{taskManager}" label="#{msgs['toolbar.next']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="nextNavLink"
                    renderedBean="#{taskManager.paginator}" renderedAction="hasNextPage" />
                <t:icon iconName="last" action="last" backingBean="#{taskManager}" label="#{msgs['toolbar.last']}"
                    bean="true" ajaxExecute="@this" ajaxRender="@all" formId="lastNavLink"
                    renderedBean="#{taskManager.paginator}" renderedAction="hasNextPage" />
            </t:toolbar>
        </ui:define>

        <!-- Title -->
        <ui:define name="content-title">
            <h1>#{msgs["user.project.detail.title"]}</h1>
        </ui:define>

        <!-- Content -->
        <ui:define name="content">
            <c:if test="#{projectManager.project.idUser == -1}">
                <script type="text/javascript" language="JavaScript">
                   window.location="list.jsf";
                </script>
            </c:if>

           <br />
           <h:outputStylesheet name="cssDetail.css" library="css" />
           <h:panelGrid columns="2" styleClass="panelDetail">
             <h:outputLabel styleClass="lbl">#{msgs["project.name"]}</h:outputLabel>
             <h:outputLabel>#{projectManager.project.name}</h:outputLabel>

             <h:outputLabel styleClass="lbl">#{msgs["project.customer"]}</h:outputLabel>
             <h:outputLabel>#{projectManager.customerName}</h:outputLabel>

             <h:outputLabel styleClass="lbl">#{msgs["project.create"]}</h:outputLabel>
             <h:outputLabel>#{projectManager.project.create}</h:outputLabel>

             <h:outputLabel styleClass="lbl">#{msgs["project.rateType"]}</h:outputLabel>
             <c:choose>
                <c:when test="#{projectManager.project.rateType == 'p'}">
                    <h:outputLabel>#{msgs["project.rateType.project"]}</h:outputLabel>
                </c:when>
                <c:when test="#{projectManager.project.rateType == 'h'}">
                    <h:outputLabel>#{msgs["project.rateType.hours"]}</h:outputLabel>
                </c:when>
                <c:when test="#{projectManager.project.rateType == 't'}">
                    <h:outputLabel>#{msgs["project.rateType.tariff"]}</h:outputLabel>
                </c:when>
             </c:choose>

             <h:outputLabel styleClass="lbl">#{msgs["project.pricePerRateUnit"]}</h:outputLabel>
             <h:outputLabel>#{projectManager.project.pricePerRateUnit}</h:outputLabel>

             <h:outputLabel styleClass="lbl">#{msgs["project.timeEstimation"]}</h:outputLabel>
             <h:outputLabel>#{projectManager.project.timeEstimation}</h:outputLabel>

             <h:outputLabel styleClass="lbl">#{msgs["project.note"]}</h:outputLabel>
             <h:outputLabel>#{projectManager.project.note}</h:outputLabel>

             <h:outputLabel styleClass="lbl">#{msgs["project.isActive"]}</h:outputLabel>
             <c:choose>
                <c:when test="#{projectManager.project.isActive == 'y'}">
                    <h:outputLabel>#{msgs["project.yes"]}</h:outputLabel>
                </c:when>
                <c:when test="#{projectManager.project.isActive == 'n'}">
                    <h:outputLabel>#{msgs["project.no"]}</h:outputLabel>
                </c:when>
             </c:choose>

           </h:panelGrid>

            <c:choose>
                <c:when test="#{taskManager.projectTasksCount > 0}">
                    <br />
                    <h2><h:outputLabel styleClass="">#{msgs["project.detail.tasks"]}</h:outputLabel></h2>

                    <!-- Task Listing -->
                    <h:outputStylesheet name="cssTable.css" library="css" />
                    <h:outputScript library="scripts" name="timer.js" />
                    <h:dataTable id="taskTable"
                                 value="#{taskManager.list}"
                                 var="task"
                                 styleClass="listing"
                                 rowClasses="odd,even"
                                 columnClasses="name, note, pricePerRateUnit, time, time, actions">
                        <t:column  headerCssStyle="listing-header" entity="${task}"
                                   fieldName="name" backingBean="#{taskManager}"
                                   label="#{msgs['user.project.detail.taskList.name']}">
                            #{task.name}
                        </t:column>
                        <t:column  sort="false" entity="${task}"
                                   fieldName="note" backingBean="#{taskManager}"
                                   label="#{msgs['user.project.detail.taskList.note']}">
                            #{task.note}
                        </t:column>
                        <t:column  sort="false" entity="${task}"
                                   fieldName="overheadCost" backingBean="#{taskManager}"
                                   label="#{msgs['user.project.detail.taskList.overheadCost']}">
                            #{task.overheadCost}
                        </t:column>

                        <t:column  entity="${task}"
                                   fieldName="time" backingBean="#{taskManager}"
                                   label="#{msgs['user.project.detail.taskList.totalTime']}">
                            <h:outputLabel rendered="#{taskManager.timer}">
                                <div id="totalTimer_#{taskManager.timerTask}">
                                </div>
                            </h:outputLabel>
                            <h:outputScript>
                            initTimerArray(#{taskManager.timerTotalMsec}, #{taskManager.isTimerStart}, 'totalTimer_#{taskManager.timerTask}');
                            </h:outputScript>

                        </t:column>

                        <t:column  entity="${task}"
                                   fieldName="time" backingBean="#{taskManager}"
                                   label="#{msgs['user.project.detail.taskList.time']}">
                            <h:outputLabel rendered="#{taskManager.timer}">
                                <div id="timer_#{taskManager.timerTask}">
                                </div>
                            </h:outputLabel>
                            <h:outputScript>
                            initTimerArray(#{taskManager.timerMsec}, #{taskManager.isTimerStart}, 'timer_#{taskManager.timerTask}');
                            </h:outputScript>

                        </t:column>


                        <t:columnCommand label="#{msgs['user.project.list.actions']}">
                            <h:commandButton value="#{msgs['user.project.detail.tasklist.actions.starttimer']}" action="#{taskManager.getStartTimer}" rendered="#{!taskManager.isTimerStart}" >
                                <f:ajax execute="@all" render="@form"  onevent="showTaskIndicator" />
                            </h:commandButton>
                            <h:commandButton value="#{msgs['user.project.detail.tasklist.actions.stoptimer']}" action="#{taskManager.saveRow}" rendered="#{taskManager.isTimerStart}">
                                <f:ajax execute="@all" render="@all" onevent="showStopForm" />
                            </h:commandButton>
                            <h:commandButton value="#{msgs['user.project.detail.tasklist.actions.edit']}" action="#{taskManager.edit}" />
                            <h:commandButton value="#{msgs['user.project.detail.tasklist.actions.detail']}" action="#{taskManager.detail}" />
                        </t:columnCommand>
                    </h:dataTable>

                    <!-- DIALOG -->
                    <h:outputScript library="scripts" name="modalForm.js" />
                    <h:outputStylesheet library="css" name="modalForm.css" />

                    <div id="dialogForm">
                        <div id="dialogBox">
                        <h:outputLabel>#{msgs["user.project.detail.tasklist.actions.createNote"]}<br /><br /></h:outputLabel>
                        
                        <h:inputTextarea id="intervalNote" value="#{taskManager.intervalNote}" rows="5" cols="30" /><br /><br />
                        <h:commandButton action="#{taskManager.stopTimer}" rendered="true" id="formButton" value="#{msgs['user.project.detail.tasklist.actions.save']}">
                             <f:ajax execute="@all" render="@all" onevent="closeStopForm" />
                        </h:commandButton>

                        </div>
                    <div id="maskModal"></div>
                </div>
                <!-- END DIALOG -->

                    <!-- AJAX navigation -->
                    <h:commandLink id="prevLink" action="#{taskManager.previous}"
                                    value="Previous #{taskManager.paginator.pageSize}"
                                    rendered="#{taskManager.paginator.hasPreviousPage}">
                        <f:ajax execute="@this" render="@form" />
                    </h:commandLink>

                    <h:outputText value="#{taskManager.paginator.pageFirstItem + 1} to #{taskManager.paginator.pageLastItem + 1} of #{taskManager.paginator.itemsCount}"/>
                    <h:outputText value=" Page: #{taskManager.paginator.actualPage + 1} " />

                    <h:commandLink id="nextLink" action="#{taskManager.next}"
                                   value="Next #{taskManager.paginator.pageSize}"
                                   rendered="#{taskManager.paginator.hasNextPage}">
                        <f:ajax execute="@this" render="@form" />
                    </h:commandLink>
                </c:when>
                <c:otherwise>
                    <p class="warning-messages-noitems">
                        #{msgs['app.listing.task.no-records']}
                    </p>
                </c:otherwise>
            </c:choose>
       </ui:define>

    </ui:composition>

</h:body>
</html>
